package io.gitee.hchaojie.day05;

import org.junit.Test;

import java.util.HashSet;
import java.util.Set;

public class TestSet {
    @Test
    public void test() {
        Set<String> set = new HashSet<>();
        
        boolean result = set.add("张三");
        System.out.println(result);
        
        result = set.add("张三");
        System.out.println(result);
        
        result = set.add("李四");
        System.out.println(result);
        
        System.out.println(set.size());
    }
    
    @Test
    public void test2() {
        Set<Teacher> teachers = new HashSet<>();
        teachers.add(new Teacher("张三"));
        teachers.add(new Teacher("张三"));
        teachers.add(new Teacher("李四"));
        
        System.out.println(teachers.size());
        
        Set<Student> students = new HashSet<>();
        students.add(new Student("张三", 18, "10001"));
        students.add(new Student("张三", 18, "10001"));
        students.add(new Student("李四", 28, "10002"));
        System.out.println(students.size());
    }

    // 求数组不重复元素的个数
    @Test
    public void test3() {
        int[] arrays = {1, 1, 3, 3, 8, 9};

        Set<Integer> set = new HashSet<>();
        for (int i : arrays) {
            set.add(i);     // 自动拆箱     包装类型 =》 基本类型
        }
        
        System.out.println(set);
    }
}
